import Explorer.config as G

from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render

from Utils.utils import Controller
from Explorer.user import *
from Explorer.explorer import *

from Editor.editor import *
def static_cry(request,path):
    return HttpResponseRedirect('/static/'+path)
def test(request):
    return Controller.show_json({"re":"re"})

def index(request):
    path, default, state = Controller.get_data_base_dir()
    if not state:
        return HttpResponseRedirect('/')
    context ={
        "config":G.CONFIG,
        "user":G.USERINFO,
        "LNG":G.LNG,
        "b":2,
        "title":"title"
    }
    return render(request,'Editor/index.html',context )

def indexphp(request):
    req = request.GET


    if (req.__contains__("user/commonJs")):
        user = User()
        return user.commonJs(request,req['st'],req['act'])

    if (req.__contains__("explorer/treeList")):
        explorer = Explorer()
        return explorer.treelist(req['app'],req['type'],)

    editor = Editor()
    if(req.__contains__("editor/edit")):
        return editor.edit(request)
    if(req.__contains__("editor/edit")):
        return editor.edit(request)

    if (req.__contains__("explorer")):
        if(req['type']=="iframe"):
            return render(request,"Editor/iframe_explorer.html")

    explorer = Explorer()
    if (req.__contains__("explorer/pathList")):
        return explorer.pathlist(req['path'])
    if (req.__contains__("explorer/treeList")):
        return explorer.treelist(req['app'], req['type'])
    if (req.__contains__("explorer/image")):
        return explorer.image(request, req['path'], req['time'])

    ret = {"remark":"not match","GET":req}
    return Controller.show_json(ret)




